package com.pms.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

public class DateJsonValueProcessor implements JsonValueProcessor{

	public static final String Default_DATE_PATTERN = "yyyy-MM-dd";
	private DateFormat dateFormat;

	public DateJsonValueProcessor(String datePattern){
	    try
	    {
	      this.dateFormat = new SimpleDateFormat(datePattern);
	    }
	    catch (Exception e) {
	      this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	    }
	 }
	
	
	@Override
	public Object processArrayValue(Object value, JsonConfig arg1) {
		return process(value);
	}

	@Override
	public Object processObjectValue(String key, Object value, JsonConfig arg2) {
		return process(value);
	}

	private Object process(Object value) {
		if(value == null)
			return "--";
		return this.dateFormat.format((Date)value);
		
	}
}
